#include "ThreadPool.h"

int tcpInit(int *psockFd, const char *ip, const char *port){
    *psockFd = socket(AF_INET, SOCK_STREAM, 0);

    int reuse = 1;
    int ret = setsockopt(*psockFd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
    ERROR_CHECK(ret, -1, "setsockopt");

    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = inet_addr(ip);
    addr.sin_port = htons(atoi(port));
    ret = bind(*psockFd ,(struct sockaddr *)&addr, sizeof(addr));
    ERROR_CHECK(ret, -1, "bind");

    listen(*psockFd, 50);
    return 0;
}